<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="tag" uri="surveyonline-taglib" %>

<%@ page import="fr.univ.surveyonline.model.User" %>
<%@ page import="fr.univ.surveyonline.model.allEnum.Role" %>
<%@ page import="fr.univ.surveyonline.model.Survey" %>
<%@ page import="fr.univ.surveyonline.model.ResponseManager" %>
<%@ page import="java.util.*" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<%@page import="fr.univ.surveyonline.model.DateHelpers"%><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
<head>
    <title><tag:languageTag id="title"/></title>
	<%@ include file="/layout/head.tag" %>
</head>
<body>

<div id="global">
	<div id="entete">
		<%@ include file="/layout/menu.tag" %>
	</div>
	<div id="contenu">
		<h2><tag:languageTag id="profil_title"/></h2>
		<% 
			User u = null;
			if (request.getSession().getAttribute("user") == null) {
				String message = "Vous devez vous connecter pour acceder au profil";
				request.setAttribute("message", message);
				RequestDispatcher rd = request.getRequestDispatcher("unaccessible.jsp");
				try {
					rd.forward(request, response);
				} catch (ServletException e) {
					e.printStackTrace();
				}			
			} else {
				u = (User) request.getSession().getAttribute("user");
			}
		%>
		<p><tag:languageTag id="profil_desc"/></p>
		<div style="float:left">
			<img src="images/user_profile.png" alt="user" style="margin-left:50px;margin-top:60px"/>	
			<br/><br/><br/><br/>
			<form action="modifier-profil.jsp">
				<input type="submit" style="margin-left:180px" value="<tag:languageTag id="profil_modify"/>" />
			</form>
		</div>
		
		<div style="float:right;width:350px">
			<div id="form_id">
			<h3 style="padding-left:100px;"><tag:languageTag id="profil_ident"/></h3>
			<ul>
				<li>
					<p>
						<label><tag:languageTag id="profil_log"/></label>
						<em><% if(u != null) out.print(u.getLogin());%></em>
					</p>
				</li>
			</ul>
			
			
			<h3 style="padding-left:100px;"><tag:languageTag id="profil_bank"/></h3>
			<ul>
				<li>
					<p>
						<label><tag:languageTag id="profil_bank_amount"/></label>
						<em><% if(u != null) out.print(u.getMoney());%></em>
					</p>
				</li>
			</ul>
			</div>
			<div id="form_info_profil">
			<h3 style="padding-left:100px;"><tag:languageTag id="profil_who"/></h3>
			<ul>
				<li>
					<p>
						<label><tag:languageTag id="profil_firstname"/></label>
						<em><% if(u != null) out.print(u.getFirstName());%></em>
					</p>
				</li>
				<li>
					<p>
						<label><tag:languageTag id="profil_lastname"/></label>
						<em><% if(u != null) out.print(u.getLastName());%></em>
					</p>
				</li>
				<li>
					<p>
						<label><tag:languageTag id="index_birth"/><br/><tag:languageTag id="index_birth_2"/></label>
						<em><% int month = u.getBirthday().getMonth()+1;
						int day = u.getBirthday().getDate();
						int year = u.getBirthday().getYear()+1900;
						if ((month < 10) && (day < 10)) {
							out.print("0" + day + "/0" + month + "/" + year);							
						} else if (month < 10) {
							out.print(day + "/0" + month + "/" + year);
						} else if (day < 10) {
							out.print("0" + day + "/" + month + "/" + year);
						} else {
							out.print(day + "/" + month + "/" + year);
						}
						//if(u != null) out.print(DateHelpers.dateToString(u.getBirthday()));
						%></em>
					</p>
				</li>
				<li>
					<p>
						<label><tag:languageTag id="profil_sexe"/></label>
						<em><% if(u != null){
							if (u.getSexe().toString().equals("Homme")) {
								%><tag:languageTag id="profil_sexe_m"/><%
							} else {
								%><tag:languageTag id="profil_sexe_f"/><%
							}
							//out.print(u.getSexe());
						}
						%></em>
					</p>
				</li>
				<li>
					<p>
						<label><tag:languageTag id="profil_cat"/></label>
						<em><% if(u != null) out.print(u.getCategorie());%></em>
					</p>
				</li>
				<li>
					<p>
						<label><tag:languageTag id="profil_country"/></label>
						<em><% if(u != null) out.print(u.getRegion());%></em>
					</p>
				</li>
			</ul>
			</div>
			<div id="form_contact">
			<h3><tag:languageTag id="profil_contact"/></h3>
			<ul>
				<li>
					<p >
						<tag:languageTag id="profil_email"/>
						<span style="padding-left:30px"><em>
						<% if(u != null) out.print(u.getMail());%></em></span>
					</p>
				</li>
			</ul>
			</div>
			
		</div>
		<div>
		<%
			//out.print("<p>Ensemble des sondages auquel vous avez participé</p>");
			/*List<ResponseManager> rm = (List<ResponseManager>) PMF.getAllFromClass(ResponseManager.class);
			String url2="resultats_display.jsp";
			out.print("<ul>");
			for (ResponseManager res : rm) {
				if ((res.getUserKey().equals(u.getKey())) && (res.hasAllreadyAnswered())) {
					String query = "select from " + Survey.class.getName()
						  + " where Key=" + res.getSurveyKey();
					Survey s = (Survey) PMF.executeQuery(query);
					out.print("<li><a href=\"/"+ url2 +"?survey="+s.getKey().getId()+"\">"+ s.getName() +"</a></li>");	
				}
			}
			out.print("</ul>");*/
		%>
		</div>
		<div class="clear"></div>
	</div>
	<div id="pied">
		<%@ include file="/layout/pied.tag" %>
	</div>
</div>

</body>
</html>